﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Account.BLL;
using Yipusoft.BaseDoc.Model;
using System.IO;
using Yipusoft.BaseDoc.BLL;
using System.Data;
using SmartWeb.BLL;
using Yipusoft.Account.Model;


public partial class DocDepartmentAllList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Response.Redirect("http://10.24.10.119/Task/BaseDoc/DocumentList.aspx?RootMenuID=100000");

        Glist = new List<DocumentFileInfo>();
        menulist = new List<MenuItem>();

        if (!IsPostBack)
        {
            bindSelection();
            BindMonthList();
            BindYearList();
            ListPageContral1.SetFirstPage();

            if (Request["DepartmentID"] != null)
            {
                bindSelection();
                ddlSection.SelectedValue = Request["DepartmentID"];

            }
            Bind();
            bindSubject();
        }
    }

    void bindSelection()
    {
	UserInfo us=Yipusoft.Account.BLL.User.GetUser(Page.User.Identity.Name);
        string departmentid = us.DepartmentID;
	string usid=us.UserID;
	List<RoleInfo> lr=Yipusoft.Account.BLL.User.GetRoleList(usid);
	bool role=false;
	foreach(RoleInfo r in lr)
	{
		if(r.RoleID=="100199")
		{
			role=true;
			break;
		}
	}
        if (departmentid.Substring(0, 4) == "1300")
        {
		if(role)
		{
			ddlSection.DataSource = Department.GetList(" DepartmentId ='1300000'or DepartmentId ='1300010'or DepartmentId ='1300020'or DepartmentId ='1300030' or DepartmentId ='1300040'or DepartmentId ='1300050'  ");
			//ddlSection.DataSource = Department.GetList("DepartmentId like '" + departmentid.Substring(0, 4) + "%'");
		}
			
		else
			
		{
			ddlSection.DataSource = Department.GetList(" DepartmentId ='1300000'or DepartmentId ='1300010'or DepartmentId ='1300020'or DepartmentId ='1300030' or DepartmentId ='1300040'or DepartmentId ='1300050'  ");
			//ddlSection.DataSource = Department.GetList("DepartmentId like '" + departmentid.Substring(0, 6) + "%'");
		}


            ddlSection.DataBind();
        }
    }

    private void bindSubject()
    {
        string DepartmentID = ddlSection.SelectedValue;
        List<DocSearchKeyInfo> list = DocSearchKey.GetList(" DepartmentId='" + DepartmentID + "' ");
        ddlSubject.Items.Clear();
        ddlSubject.Items.Add(new ListItem("----请选择----", ""));
        for (int i = 0; i < list.Count; i++)
        {
            ddlSubject.Items.Add(new ListItem(list[i].KeyWord, list[i].Id.ToString()));
        }
    }

    protected void ddlSubject_TextChanged(object sender, EventArgs e)
    {
        if (ddlSubject.SelectedItem.Text.Trim() != "")
        {
            string DepartmentID = ddlSection.SelectedValue;
            string ParentID = "";
            if (Request["ID"] != null)
            {
                ParentID = Request["ID"];
            }
            Response.Redirect("DocDepartmentResult.aspx?Key=" + Server.UrlEncode(ddlSubject.SelectedItem.Text) + "&Year=" + YearList.SelectedValue + "&SM=" + StartMonth.SelectedValue + "&EM=" + EndMonth.SelectedValue + "&DepartmentID=" + DepartmentID + "&ParentID=" + ParentID);
        }
    }
    #region
    private void BindYearList()
    {
        for (int i = 2006; i <= 2050; i++)
        {
            ListItem li = new ListItem();
            li.Text = i.ToString() + "年";
            li.Value = i.ToString();
            YearList.Items.Add(li);
        }
        YearList.SelectedValue = DateTime.Now.Year.ToString();

        if (Request["Year"] != null)
        {
            YearList.SelectedValue = Request["Year"];
        }
        if (Request["SM"] != null)
        {
            StartMonth.SelectedValue = Request["SM"];

        }
        if (Request["EM"] != null)
        {
            EndMonth.SelectedValue = Request["EM"];

        }
        else
        {

        }
        if (Request["EM"] != null && Request["EM"] != Request["SM"])
        {
            YearList.Enabled = false;
            StartMonth.Enabled = false;
            EndMonth.Enabled = false;
        }
        else
        {
            YearList.Enabled = true;
            StartMonth.Enabled = true;
            EndMonth.Enabled = true;

        }
    }

    private void BindMonthList()
    {
        for (int i = 1; i <= 12; i++)
        {
            ListItem li = new ListItem();
            li.Text = i.ToString() + "月";
            li.Value = i.ToString();
            EndMonth.Items.Add(li);
        }
        EndMonth.SelectedValue = DateTime.Now.Month.ToString();
        for (int i = 1; i <= 12; i++)
        {
            ListItem li = new ListItem();
            li.Text = i.ToString() + "月";
            li.Value = i.ToString();
            StartMonth.Items.Add(li);
        }
        StartMonth.SelectedValue = DateTime.Now.Month.ToString();
    }
    #endregion

    List<DocumentFileInfo> Glist = null;
    List<MenuItem> menulist = null;
    string DepartmentID = "";


    private void Bind()
    {
        //部门为总部门 显示分部门

 //if (ddlSection.SelectedValue.Substring(4, 1) == "0")
   if (ddlSection.SelectedValue == "1300000")
         {
                divDepartment.Visible = true;
                divFile.Visible = false;
               // List<DepartmentInfo> departments = Department.GetList(" DepartmentId like '" + ddlSection.SelectedValue.Substring(0, 6) + "_' and  DepartmentId not like '%0'");
                List<DepartmentInfo> departments = Department.GetList(" DepartmentId ='1300010'or DepartmentId ='1300020'or DepartmentId ='1300030' or DepartmentId ='1300040'or DepartmentId ='1300050'  ");
                
		GVDepartment.DataSource = departments;
                GVDepartment.DataBind();
            }

       else
        
        {


            //部门为分部门显示文件
            divDepartment.Visible = false;
            divFile.Visible = true;

            Glist.Clear();
            menulist.Clear();
            MenuItem item = new MenuItem();
            item.Text = "根目录";
            item.Value = Guid.Empty.ToString();
            item.NavigateUrl = "DocumentList1.aspx";
            //menupath.Items.Add(item);

            lblDocSum.Text = "0";
            if (Request["ID"] == null && Request["ID"] != "00000000-0000-0000-0000-000000000000")
            {

                if (StartMonth.SelectedValue == EndMonth.SelectedValue)
                {
                    string StartDate = YearList.SelectedValue + "-" + StartMonth.SelectedValue + "-1";
                    string EndDate = YearList.SelectedValue + "-" + EndMonth.SelectedValue + "-1";
                    EndDate = Convert.ToDateTime(EndDate).AddMonths(1).ToString();

                    string DepartmentID = ddlSection.SelectedValue;
                    string where = " DepartmentID='" + DepartmentID + "' And ParentID='" + Guid.Empty + "' and (StartDate>='" + StartDate + "') and (StartDate<'" + EndDate + "') and isFolder=1  Order by OldFileName";
                    List<DocumentFileInfo> list = Yipusoft.BaseDoc.BLL.FileManager.GetList(where);
                    int mun = 1;
                    DocumentFileInfo tempInfo = new DocumentFileInfo();
                    tempInfo.Level = 0;
                    tempInfo.OldFileName = "临时文件夹";
                    tempInfo.Format = "Folder";
                    tempInfo.Num = 1;
                    tempInfo.IsMonth = false;
                    tempInfo.IsFolder = true;
                    tempInfo.NewFileName = "临时文件夹";
                    tempInfo.OldFileName = " <img src= \"../../Images/ico/" + tempInfo.Format + ".gif\" />&nbsp;&nbsp;" + tempInfo.OldFileName;
                    tempInfo.IsFolder = true;
                    tempInfo.ParentID = Guid.Empty;
                    tempInfo.OldFileName = tempInfo.OldFileName;
                    tempInfo.StartDate = Convert.ToDateTime(StartDate);
                    tempInfo.FileSize = FileManager.GetTempFileSize(DepartmentID, Convert.ToInt32(YearList.SelectedValue), Convert.ToInt32(StartMonth.SelectedValue));

                    tempInfo.FileCount = 0;
                    mun++;
                    Glist.Add(tempInfo);
                    //文件总数
                    lblDocSum.Text = Convert.ToString(Convert.ToInt32(lblDocSum.Text) + Yipusoft.BaseDoc.BLL.FileManager.GetTempFileCount(DepartmentID, Convert.ToDateTime(StartDate).Year, Convert.ToDateTime(StartDate).Month, false));

                    foreach (DocumentFileInfo info in list)
                    {

                        if (!info.IsFolder)
                        {
                            lblDocSum.Text = Convert.ToString(Convert.ToInt32(lblDocSum.Text) + 1);
                        }
                        info.Num = mun;
                        mun++;
                        info.OldFileName = " <img src= \"../../Images/ico/" + info.Format + ".gif\" />&nbsp;&nbsp;" + info.OldFileName;
                        Glist.Add(info);
                        OrderItem(info.ID);
                    }

                    gvwFileList.Caption = "<span>" + Convert.ToString((CNum)Convert.ToInt32(StartMonth.SelectedValue)) + "月份档案列表</span>";
                }
                else//开始月份与结束月份不同
                {
                    int iSM = Convert.ToInt32(StartMonth.SelectedValue);
                    int iEM = Convert.ToInt32(EndMonth.SelectedValue);
                    string StartDate = YearList.SelectedValue + "-" + iSM + "-1";
                    string EndDate = YearList.SelectedValue + "-" + EndMonth.SelectedValue + "-1";
                    EndDate = Convert.ToDateTime(EndDate).AddMonths(1).ToString();

                    string DepartmentID = ddlSection.SelectedValue;
                    string where = " DepartmentID='" + DepartmentID + "' And ParentID='" + Guid.Empty + "' and (StartDate>='" + StartDate + "') and (StartDate<'" + EndDate + "')";

                    DataTable dt = FileManager.GetMonthFileCount(where);
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DocumentFileInfo info = new DocumentFileInfo();
                        info.Level = 0;
                        info.OldFileName = Convert.ToString((CNum)dt.Rows[i][0]) + "月份";
                        info.Format = "";
                        info.Num = -1;
                        info.IsMonth = true;
                        info.IsFolder = true;
                        info.NewFileName = i.ToString();
                        info.Month = Convert.ToInt32(dt.Rows[i][0]);
                        info.IsFolder = true;
                        info.FileCount = Convert.ToInt32(dt.Rows[i][1]);
                        info.OldFileName = " <img src= \"../../Images/ico/book.gif\"/>&nbsp;&nbsp;" + info.OldFileName;
                        info.FileCount = Convert.ToInt32(dt.Rows[i][1]);
                        info.FileSize = FileManager.GetMonthFileSize(DepartmentID, Convert.ToInt32(YearList.SelectedValue), Convert.ToInt32(dt.Rows[i][0]));

                        Glist.Add(info);
                        GetMonthFile(Convert.ToInt32(dt.Rows[i][0]));

                    }

                    gvwFileList.Caption = "<span>" + Convert.ToString((CNum)Convert.ToInt32(StartMonth.SelectedValue)) + "月份至" + Convert.ToString((CNum)Convert.ToInt32(EndMonth.SelectedValue)) + "月份档案列表</span>";
                }
            }
            else if (Request["ID"] == "00000000-0000-0000-0000-000000000000")
            {
                tempOrderItem(Request["year"], Request["SM"]);

                // string temp = string.Empty;
                //temp = "<strong>路径: </strong><a href='DocumentList.aspx'>根目录</a>\\";

                //temp += "<a href='DocumentList.aspx?Year=" + YearList.SelectedValue + "&SM=" + StartMonth.SelectedValue + "&EM=" + EndMonth.SelectedValue + "&ID=00000000-0000-0000-0000-000000000000'>临时文件夹</a>\\";

                //filepath.InnerHtml = temp;
                gvwFileList.Caption = "<span>档案列表</span>";
            }
            else
            {
                OrderItem(new Guid(Request["ID"]));

                string temp = string.Empty;
                temp = "<strong>路径: </strong><a href='DocDepartmentAllList.aspx?Year=" + YearList.SelectedValue + "&SM=" + StartMonth.SelectedValue + "&EM=" + EndMonth.SelectedValue + "&DepartmentID=" + ddlSection.SelectedValue + "'>根目录</a>\\";
                if (menulist.Count > 0)
                {
                    int count = menulist.Count;
                    for (int i = count - 1; i >= 0; i--)
                    {
                        temp += "<a href='DocumentList.aspx?Year=" + YearList.SelectedValue + "&SM=" + StartMonth.SelectedValue + "&EM=" + EndMonth.SelectedValue + "&ID=" + menulist[i].Value + "'>" + menulist[i].Text + "</a>\\";
                    }
                }
                //filepath.InnerHtml = temp;
            }
            gvwFileList.DataSource = Glist;
            ListPageContral1.ItemCount = Glist.Count();
            gvwFileList.DataBind();
        }
    }

    private void tempOrderItem(string Year, string Month)
    {
        string DepartmentID = ddlSection.SelectedValue;
        string where = " Departmentid='" + DepartmentID + "' and ParentID='00000000-0000-0000-0000-000000000000' and year(StartDate)=" + Year + " and Month(StartDate)=" + Month + " and isFolder=0  Order by OrderID ";


        List<Yipusoft.BaseDoc.Model.DocumentFileInfo> list = Yipusoft.BaseDoc.BLL.FileManager.GetList(where);
        int mun = 1;
        if (list != null)
        {
            foreach (DocumentFileInfo info in list)
            {
                info.OldFileName = " <img src= \"../../Images/ico/" + info.Format + ".gif\" />" + info.OldFileName;
                info.Num = mun;
                mun++;
                var pp = from o in Glist where info.ID == o.ID select o;
                if (pp.Count() == 0)
                {
                    Glist.Add(info);
                }
                else
                {

                }
                OrderItem(info.ID);
            }
        }


        list = Yipusoft.BaseDoc.BLL.FileManager.GetList(where);
        if (list != null)
        {
            foreach (DocumentFileInfo info in list)
            {
                if (!info.IsFolder)
                {
                    lblDocSum.Text = Convert.ToString(Convert.ToInt32(lblDocSum.Text) + 1);
                }
            }
        }
    }

    private void GetMonthFile(int i)
    {
        string StartDate = YearList.SelectedValue + "-" + i + "-1";
        string EndDate = Convert.ToDateTime(StartDate).AddMonths(1).ToString();
        string DepartmentID = ddlSection.SelectedValue;
        string where = " DepartmentID='" + DepartmentID + "' And ParentID='" + Guid.Empty + "' and (StartDate>='" + StartDate + "') and (StartDate<'" + EndDate + "') and isFolder=1  Order by StartDate, OrderID";
        List<DocumentFileInfo> list = Yipusoft.BaseDoc.BLL.FileManager.GetList(where);
        int mun = 1;
        DocumentFileInfo tempInfo = new DocumentFileInfo();
        tempInfo.Level = 1;
        tempInfo.OldFileName = "临时文件夹";
        tempInfo.Format = "Folder";
        tempInfo.Num = 1;
        tempInfo.IsMonth = false;
        tempInfo.IsFolder = true;
        tempInfo.ParentID = Guid.Empty;
        tempInfo.NewFileName = "临时文件夹";
        tempInfo.OldFileName = " <img src= \"../../Images/ico/" + tempInfo.Format + ".gif\" />&nbsp;&nbsp;" + tempInfo.OldFileName;
        tempInfo.IsFolder = true;
        tempInfo.StartDate = Convert.ToDateTime(StartDate);
        tempInfo.OldFileName = tempInfo.OldFileName;
        tempInfo.FileCount = 0;
        tempInfo.FileSize = FileManager.GetTempFileSize(DepartmentID, Convert.ToInt32(YearList.SelectedValue), i);
        Glist.Add(tempInfo);

        //文件总数
        lblDocSum.Text = Convert.ToString(Convert.ToInt32(lblDocSum.Text) + Yipusoft.BaseDoc.BLL.FileManager.GetTempFileCount(DepartmentID, Convert.ToDateTime(StartDate).Year, i, false));

        mun++;
        foreach (DocumentFileInfo info in list)
        {

            if (!info.IsFolder)
            {
                lblDocSum.Text = Convert.ToString(Convert.ToInt32(lblDocSum.Text) + 1);
            }
            info.Num = mun;
            mun++;

            info.OldFileName = " <img src= \"../../Images/ico/" + info.Format + ".gif\" />&nbsp;&nbsp;" + info.OldFileName;
            var pp = from o in Glist where info.ID == o.ID select o;
            if (pp.Count() == 0)
            {
                Glist.Add(info);
            }
            OrderItem(info.ID);
        }
    }

    public string GetChildCount(object objID)
    {
        if (objID == null)
            return "0";
        int temp = Yipusoft.BaseDoc.BLL.FileManager.GetChildFileCount((Guid)objID, true);
        DocumentFileInfo info = Yipusoft.BaseDoc.BLL.FileManager.GetFile(new Guid(objID.ToString()));
        if (info == null)
        {
            return "";
        }
        if (Yipusoft.BaseDoc.BLL.FileManager.GetFile((Guid)objID).ParentID.Equals(Guid.Empty))
            return "<font color=red>" + temp + "</font>";
        else
            return temp.ToString();

    }
    public void ListPageContral1_PageSizeChange(int pageSize, int PageIndex)
    {
        gvwFileList.PageIndex = PageIndex;
        Bind();
    }

    private void OrderItem(Guid ID)
    {

        string FileCountwhere = "  ParentID='" + ID + "' Order by OldFileName ";
        string where = string.Empty;
        if (Request["ID"] == null)
            where = " IsFolder='True'  And ParentID='" + ID + "' Order by OldFileName ";
        else
        {
            where = "  ParentID='" + ID + "' Order by OldFileName ";

        }
        List<Yipusoft.BaseDoc.Model.DocumentFileInfo> list = Yipusoft.BaseDoc.BLL.FileManager.GetList(where);
        int mun = 1;
        if (list != null)
        {
            foreach (DocumentFileInfo info in list)
            {
                info.OldFileName = " <img src= \"../../Images/ico/" + info.Format + ".gif\" />" + info.OldFileName;
                info.Num = mun;
                mun++;
                Glist.Add(info);
                OrderItem(info.ID);
            }
        }
        list = Yipusoft.BaseDoc.BLL.FileManager.GetList(FileCountwhere);
        if (list != null)
        {
            foreach (DocumentFileInfo info in list)
            {
                if (!info.IsFolder)
                {
                    lblDocSum.Text = Convert.ToString(Convert.ToInt32(lblDocSum.Text) + 1);
                }
            }
        }
    }

    public string GetChar(object objID)
    {
        DocumentFileInfo info = Yipusoft.BaseDoc.BLL.FileManager.GetFile(new Guid(objID.ToString()));
        if (info == null)
        {
            return "";
        }
        else
        {
            return "".PadLeft(2 * info.Level.Value, '　');
        }
    }

    protected void ddlDepartment_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindSelection();
    }
    protected void ddlSection_SelectedIndexChanged(object sender, EventArgs e)
    {
        DepartmentID = ddlSection.SelectedValue;

        Session["TempDepartmentID"] = DepartmentID;

        ListPageContral1.SetFirstPage();

        bindSubject();
        Bind();
    }
    protected void gvwFileList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DepartmentID = ddlSection.SelectedValue;
            //文件数量
            Label lblFileCount = e.Row.FindControl("lblFileCount") as Label;
            //LinkButton btn = e.Row.FindControl("LinkButton1") as LinkButton;
            //if (btn == null)
            //    return;
            //btn.PostBackUrl = "DocumentList1.aspx?ID=" + btn.CommandArgument;
            LinkButton btn = e.Row.FindControl("LinkButton1") as LinkButton;
            DocumentFileInfo fileinfo = e.Row.DataItem as DocumentFileInfo;
            if (fileinfo.IsMonth)//月份
            {
                CheckBox CheckBox1 = e.Row.FindControl("CheckBox1") as CheckBox;
                CheckBox1.Visible = false;
                LinkButton LinkButton1 = e.Row.FindControl("LinkButton1") as LinkButton;
                LinkButton1.CommandName = "mt";
                LinkButton1.CommandArgument = fileinfo.Month.ToString();
                LinkButton1.ToolTip = ((CNum)fileinfo.Month).ToString() + "月份";

                e.Row.BackColor = System.Drawing.Color.FromName("#F5FBF9");
                lblFileCount.Text = FileManager.GetMonthFileCount(DepartmentID, Convert.ToInt32(YearList.SelectedValue), fileinfo.Month).ToString();
                lblFileCount.ForeColor = System.Drawing.Color.Green;
                //lblFileCount.Text =

            }
            else
            {

                lblFileCount.Text = GetChildCount(fileinfo.ID);
            }

            if (fileinfo.ParentID == Guid.Empty && fileinfo.IsFolder && fileinfo.NewFileName == "临时文件夹")
            {
                btn.ToolTip = "临时文件夹";

                btn.CommandName = "ls";
                btn.CommandArgument = "DocDepartmentAllList1.aspx?Year=" + fileinfo.StartDate.Value.Year + "&SM=" + fileinfo.StartDate.Value.Month + "&EM=" + fileinfo.StartDate.Value.Month + "&ID=00000000-0000-0000-0000-000000000000&DepartmentID=" + DepartmentID;
                //临时文件夹中文件的数量

                lblFileCount.Text = FileManager.GetTempFileCount(DepartmentID, fileinfo.StartDate.Value.Year, fileinfo.StartDate.Value.Month, false).ToString();
            }
        }
    }

    protected void LinkButton1_Command(object sender, CommandEventArgs e)
    {
        DocumentFileInfo info = Yipusoft.BaseDoc.BLL.FileManager.GetFile(new Guid(e.CommandArgument.ToString()));
        if (info.Format == "Folder")
            Response.Redirect("DocDepartmentAllList1.aspx?Year=" + YearList.SelectedValue + "&SM=" + StartMonth.SelectedValue + "&EM=" + EndMonth.SelectedValue + "&DepartmentID=" + ddlSection.SelectedValue + "&ID=" + e.CommandArgument.ToString());
        else
            DownLoad(info.NewFileName, info.OldFileName, info.FilePath);

    }

    private void DownLoad(string name, string oldFileName, string filePath)
    {
        string fileName = name;//客户端保存的文件名       

        FileInfo fileInfo = new FileInfo(Server.MapPath(filePath));
        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
        Response.AddHeader("Content-Length", fileInfo.Length.ToString());
        Response.AddHeader("Content-Transfer-Encoding", "binary");
        Response.ContentType = "application/octet-stream";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
        Response.WriteFile(fileInfo.FullName);
        Response.Flush();
        Response.End();

    }
    protected void YearList_SelectedIndexChanged(object sender, EventArgs e)
    {
        Bind();
    }
    protected void StartMonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        Bind();
    }
    protected void EndMonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        Bind();
    }
    protected void gvwFileList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //if (e.CommandName == "re")
        //{
        //    DocumentFileInfo info = Yipusoft.BaseDoc.BLL.FileManager.GetFile(new Guid(e.CommandArgument.ToString()));
        //    if (info.Format == "Folder")
        //        Response.Redirect("DocDepartmentList1.aspx?Year=" + YearList.SelectedValue + "&SM=" + StartMonth.SelectedValue + "&EM=" + EndMonth.SelectedValue + "&DepartmentID=" + ddlSection.SelectedValue + "&ID=" + e.CommandArgument.ToString());
        //    else
        //        DownLoad(info.NewFileName, info.OldFileName, info.FilePath);
        //}
        //if (e.CommandName == "mt")
        //{
        //    Response.Redirect("DocDepartmentList.aspx?Year=" + YearList.SelectedValue + "&SM=" + e.CommandArgument + "&EM=" + e.CommandArgument);
        //}

        if (e.CommandName == "re")
        {
            DocumentFileInfo info = Yipusoft.BaseDoc.BLL.FileManager.GetFile(new Guid(e.CommandArgument.ToString()));
            if (info == null)
            {

            }
            else
            {
                if (info.Format == "Folder")
                    Response.Redirect("DocDepartmentAllList1.aspx?Year=" + YearList.SelectedValue + "&SM=" + StartMonth.SelectedValue + "&EM=" + EndMonth.SelectedValue + "&departmentId=" + ddlSection.SelectedValue + "&ID=" + e.CommandArgument.ToString());
                else
                    DownLoad(info.NewFileName, info.OldFileName, info.FilePath);
            }
        }
        if (e.CommandName == "mt")//月份操作
        {
            Response.Redirect("DocDepartmentAllList.aspx?Year=" + YearList.SelectedValue + "&SM=" + e.CommandArgument + "&EM=" + e.CommandArgument);
        }

        if (e.CommandName == "ls")
        {
            Response.Redirect(e.CommandArgument.ToString());
        }
    }
    protected void lkbZX_Click(object sender, EventArgs e)
    {
        string IDs = "";
        // foreach (GridViewRow row in gvwFileList.Rows)
        for (int i = 0; i < gvwFileList.Rows.Count; i++)
        {
            GridViewRow row = gvwFileList.Rows[i];
            CheckBox cbx = row.FindControl("CheckBox1") as CheckBox;
            if (cbx.Checked)
            {
                IDs += "'" + gvwFileList.DataKeys[i].Value + "',";
            }
        }

        if (IDs.Length > 0)
        {
            IDs = IDs.Remove(IDs.Length - 1);
            string departmentid = ddlSection.SelectedValue;
            Response.Redirect("DocDepartmentResult.aspx?IDs=" + Server.UrlEncode(IDs) + "&Year=" + YearList.SelectedValue + "&DepartmentID=" + departmentid);
        }

        Bind();
    }
    protected void lbtnSearch_Click(object sender, EventArgs e)
    {
        if (txtKey.Text.Trim() != "")
        {
            string DepartmentID = ddlSection.SelectedValue;
            string ParentID = "";
            if (Request["ID"] != null)
            {
                ParentID = Request["ID"];
            }
            Response.Redirect("DocDepartmentResult.aspx?Key=" + Server.UrlEncode(txtKey.Text.Trim()) + "&Year=" + YearList.SelectedValue + "&SM=" + StartMonth.SelectedValue + "&EM=" + EndMonth.SelectedValue + "&DepartmentID=" + DepartmentID + "&ParentID=" + ParentID);
        }
    }
    protected void GVDepartment_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //单位
            DepartmentInfo department = e.Row.DataItem as DepartmentInfo;
            //月份
            int Year = Convert.ToInt32(YearList.SelectedValue);
            int startMonth = Convert.ToInt32(StartMonth.SelectedValue);
            int endMonth = Convert.ToInt32(EndMonth.SelectedValue);
            //序号
            Label ID = e.Row.FindControl("lblId") as Label;
            ID.Text = e.Row.RowIndex + 1 + "、";

            int fileCount = 0;
            int fileSize = 0;
            for (int i = startMonth; i <= endMonth; i++)
            {
                fileCount += FileManager.GetMonthFileCount(department.DepartmentID, Year, i);
                fileSize += FileManager.GetMonthFileSize(department.DepartmentID, Year, i);
            }
            //数量
            Label lblFileCount = e.Row.FindControl("lblFileCount") as Label;
            lblFileCount.Text = fileCount.ToString();
            //大小
            Label lblFileSize = e.Row.FindControl("lblFileSize") as Label;
            lblFileSize.Text = fileSize.ToString();

            lblDocSum.Text = Convert.ToString(Convert.ToInt32(lblDocSum.Text) + Convert.ToInt32(lblFileCount.Text));
        }
    }
    protected void GVDepartment_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "re")
        {
            string DepartmentId = e.CommandArgument.ToString();
            ddlSection.SelectedValue = DepartmentId;
            Bind();
        }
    }
}
